package com.example.wordtris;

import com.example.wordtris.WTGameVars;
import com.example.wordtris.WTGameView;


import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.WindowManager;

public class startActivity extends Activity {
	final WTGameVars gameEngine = new WTGameVars();
	private WTGameView gameView;
	private int mActivePointerId;

		@Override
		 public void onCreate(Bundle savedInstanceState) {
		        super.onCreate(savedInstanceState);
		        WTGameVars.display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
	    	        gameView = new WTGameView(this);
		        setContentView(gameView);
		    }
		@Override
	    protected void onResume() {
	       super.onResume();
	       gameView.onResume();
	    }

	    @Override
	    protected void onPause() {
	       super.onPause();
	       gameView.onPause();
	    }
		@Override
	   	public boolean onTouchEvent(MotionEvent event) {
	   		//
			int height=0,width=0;
			mActivePointerId = event.getPointerId(0);
			Point size = new Point();
	        WTGameVars.display.getSize(size);
            width = size.x;
            height = size.y;
		    int pointerIndex = event.findPointerIndex(mActivePointerId);
		    float x = event.getX(pointerIndex);
		    float y = event.getY(pointerIndex);
	        int height1 = height / 2;
	        int playableArea = height - height1;
	        if (y > playableArea){
            final int action = event.getAction();
            switch (action & MotionEvent.ACTION_MASK){
	        	case MotionEvent.ACTION_DOWN:
	    	
	        		if(x < width / 2){
	        			WTGameVars.playerAction = WTGameVars.LETTER_MOVE_LEFT_1;
	        		}else{
	        			WTGameVars.playerAction = WTGameVars.LETTER_MOVE_RIGHT_1;
	        		}
	        		break;
	        	case MotionEvent.ACTION_UP:
	        		WTGameVars.playerAction = WTGameVars.LETTER_RELEASE;
	        		break;
	        	}
	        }
	        return false;
		}
}
